package com.bsoft.exchange.service;



import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bsoft.exchange.dao.his.CreateOrderNoMapper;
import com.bsoft.exchange.domain.CreateOrserNoDomain;
import com.bsoft.exchange.pojo.CreateOrderNoPojo;
import com.bsoft.exchange.util.BaseResponse;
import com.bsoft.exchange.util.Constant;
import com.bsoft.exchange.util.IdentityManager;

@Service
public class CreateOrderNoService {
	
	@Autowired
	CreateOrderNoMapper createOrderNoMapper;
	@Autowired
	IdentityManager identityManager ;
	
	public BaseResponse<CreateOrserNoDomain> getShddh(CreateOrderNoPojo createOrderNoPojo)  {
		BaseResponse<CreateOrserNoDomain>baseResponse=new BaseResponse<>();
		
		Integer jgid = Integer.valueOf(createOrderNoPojo.getOrganizationId());
		String ywlb = createOrderNoPojo.getBusType();
		Integer zffs = Integer.valueOf(createOrderNoPojo.getPayMode());
		Double zfje = createOrderNoPojo.getAmount();
		String brids = createOrderNoPojo.getPatientId();
		Integer zjlx = 1;
		if(createOrderNoPojo.getCardType()!=null&&!"".equals(createOrderNoPojo.getCardType())){
		zjlx = Integer.valueOf(createOrderNoPojo.getCardType());}
		
		String zjhm = createOrderNoPojo.getCardNumber();
		Integer brid = null;
		if(brids==null||"".equals(brids)){
			brid = createOrderNoMapper.getBrid(zjlx, zjhm, jgid);
		}else{
			brid = Integer.valueOf(brids);
		}
		
		if(brid == null || brid==0){
			baseResponse.setCode(Constant.errorTag);
			baseResponse.setMessage("该病人ID无效"+brid);
			return baseResponse;
		}
		
		//获取商户订单号
		Long shddh = (Long)identityManager.getMax("GY_SHDDH", 1);
		Date now = new Date();
		
		//插入订单表
		createOrderNoMapper.insertShddh(shddh.toString(), ywlb, brid, now, zfje, zffs, jgid);
		
		CreateOrserNoDomain createOrserNoDomain = new CreateOrserNoDomain();
		createOrserNoDomain.setOutOrderNumber(String.valueOf(shddh));
		
		baseResponse.setCode(Constant.successTag);
		baseResponse.setData(createOrserNoDomain);
		baseResponse.setMessage("成功");
		return baseResponse;
		
		
	}

public 	BaseResponse<String> createShddh(int jgid,int ywlb,int zffs,Double zfje,int brid){
	BaseResponse<String> baseResponse=new BaseResponse<>();
	//获取商户订单号
	Long shddh = (Long)identityManager.getMax("GY_SHDDH", 1);
	Date now = new Date();
	//插入订单表
	Integer integer = createOrderNoMapper.insertShddh(shddh.toString(), String.valueOf(ywlb), brid, now, zfje, zffs, jgid);
	if(integer > 0){
		baseResponse.setCode(Constant.successTag);
		baseResponse.setData(String.valueOf(shddh));
		baseResponse.setMessage("成功");
	}

	return baseResponse;
	
	
}

}